/*
 * @Author: xushuhao
 * @Email: xshmouse@163.com
 * @Date: 2020-05-08 11:03:55
 * @Last Modified by: xushuhao
 * @Last Modified time: 2020-07-23 11:50:04
 * @Description: 小屏播放demo 支持大屏动画切换
 */

import 'package:auto_orientation/auto_orientation.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_code_framework/widgets/x_video_player.dart';

class DemoPlayerTrans extends StatefulWidget {
  const DemoPlayerTrans({Key key}) : super(key: key);
  @override
  DemoPlayerTransState createState() {
    return DemoPlayerTransState();
  }
}

class DemoPlayerTransState extends State<DemoPlayerTrans> {
  double _height = 210;
  double _screenHeight = 0;

  _changeFullScreen(bool isFull) {
    if (isFull) {
      setState(() {
        _height = _screenHeight;
      });
      //全屏 强制横屏
      AutoOrientation.landscapeRightMode();
      //启动横屏陀螺仪
      AutoOrientation.landscapeAutoMode();
      setState(() {
        _height = MediaQuery.of(context).size.width;
      });
    } else {
      AutoOrientation.portraitUpMode();
      setState(() {
        _height = 210;
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    _screenHeight = MediaQuery.of(context).size.height;
    return Scaffold(
      body: Column(
        children: <Widget>[
          Container(
            height: _height,
            child: XVideoPlayer(
              // isMaxDisplay: false,
              path: [
                PlayerInputInstance(title: '多边形的外角和', list: [
                  VideoType(
                      name: '标清',
                      url:
                          'http://zy.wiscoor.com/XRCPlay//RC/4/2/2/941/201705/18/4f1a8237-d0ca-407a-bf18-277694f15751/video/746cd2471b0245ac8db377a306d49c3a.mp4'),
                  VideoType(
                      name: '高准',
                      url:
                          'http://zy.wiscoor.com/XRCPlay//RC/4/2/2/941/201705/18/4f1a8237-d0ca-407a-bf18-277694f15751/video/746cd2471b0245ac8db377a306d49c3a.mp4'),
                  VideoType(
                      name: '超清',
                      url:
                          'http://zy.wiscoor.com/XRCPlay//RC/4/2/2/941/201705/18/4f1a8237-d0ca-407a-bf18-277694f15751/video/3ae12334bf2c4e1d9aa8581fb2e92310.mp4')
                ]),
                PlayerInputInstance(title: '三角形的角平分线', list: [
                  VideoType(
                      name: '高清',
                      url:
                          'http://zy.wiscoor.com/XRCPlay//RC/4/2/2/941/201705/12/882b010f-74fc-413f-a54b-1a9e23470883/video/097e56983db64672b25ac83179fa409d.mp4')
                ]),
                PlayerInputInstance(title: '三角形的高', list: [
                  VideoType(
                      name: '标清',
                      url:
                          'http://zy.wiscoor.com/XRCPlay//RC/4/2/2/941/201705/12/bc5468e2-19ac-4e6e-9cee-934504a94527/video/1d5be1643c7a4995ba0dc10036c922d4.mp4'),
                  VideoType(
                      name: '高准',
                      url:
                          'http://zy.wiscoor.com/XRCPlay//RC/4/2/2/941/201705/12/bc5468e2-19ac-4e6e-9cee-934504a94527/video/39948fd01c8442d59311369cf070e1f6.mp4'),
                  VideoType(
                      name: '超清',
                      url:
                          'http://zy.wiscoor.com/XRCPlay//RC/4/2/2/941/201705/12/bc5468e2-19ac-4e6e-9cee-934504a94527/video/1d5be1643c7a4995ba0dc10036c922d4.mp4')
                ]),
                PlayerInputInstance(title: '多边形的内角和', list: [
                  VideoType(
                      name: '高清',
                      url:
                          'http://zy.wiscoor.com/XRCPlay//RC/4/2/2/941/201705/12/882b010f-74fc-413f-a54b-1a9e23470883/video/097e56983db64672b25ac83179fa409d.mp4')
                ]),
                PlayerInputInstance(title: '角的度量与比较大小', list: [
                  VideoType(
                      name: '标清',
                      url:
                          'http://zy.wiscoor.com/XRCPlay//RC/4/2/2/941/201705/18/4f1a8237-d0ca-407a-bf18-277694f15751/video/746cd2471b0245ac8db377a306d49c3a.mp4'),
                  VideoType(
                      name: '高准',
                      url:
                          'http://zy.wiscoor.com/XRCPlay//RC/4/2/2/941/201705/18/4f1a8237-d0ca-407a-bf18-277694f15751/video/746cd2471b0245ac8db377a306d49c3a.mp4'),
                  VideoType(
                      name: '超清',
                      url:
                          'http://zy.wiscoor.com/XRCPlay//RC/4/2/2/941/201705/18/4f1a8237-d0ca-407a-bf18-277694f15751/video/3ae12334bf2c4e1d9aa8581fb2e92310.mp4')
                ]),
                PlayerInputInstance(title: '角的加法与减法', list: [
                  VideoType(
                      name: '高清',
                      url:
                          'http://zy.wiscoor.com/XRCPlay//RC/4/2/2/941/201705/12/882b010f-74fc-413f-a54b-1a9e23470883/video/097e56983db64672b25ac83179fa409d.mp4')
                ]),
                PlayerInputInstance(title: '角的概念和表示方法', list: [
                  VideoType(
                      name: '标清',
                      url:
                          'http://zy.wiscoor.com/XRCPlay//RC/4/2/2/941/201705/12/bc5468e2-19ac-4e6e-9cee-934504a94527/video/1d5be1643c7a4995ba0dc10036c922d4.mp4'),
                  VideoType(
                      name: '高准',
                      url:
                          'http://zy.wiscoor.com/XRCPlay//RC/4/2/2/941/201705/12/bc5468e2-19ac-4e6e-9cee-934504a94527/video/39948fd01c8442d59311369cf070e1f6.mp4'),
                  VideoType(
                      name: '超清',
                      url:
                          'http://zy.wiscoor.com/XRCPlay//RC/4/2/2/941/201705/12/bc5468e2-19ac-4e6e-9cee-934504a94527/video/1d5be1643c7a4995ba0dc10036c922d4.mp4')
                ]),
                PlayerInputInstance(
                    title: '视频标题2视频标题2视频标题2视频标题2视频标题2视频标题2',
                    list: [
                      VideoType(
                          name: '高清',
                          url:
                              'http://zy.wiscoor.com/XRCPlay//RC/4/2/2/941/201705/12/882b010f-74fc-413f-a54b-1a9e23470883/video/097e56983db64672b25ac83179fa409d.mp4')
                    ]),
              ],
              isFullScreen: false,
              backCall: _changeFullScreen,
            ),
          ),
          // AnimatedContainer(
          //   height: _height,
          //   curve: Curves.easeIn,
          //   duration: Duration(microseconds: 350),
          //   child:
          // ),
          Expanded(
            child: Center(
                child: FlatButton(
              child: Text(
                '内容显示区',
                style: TextStyle(color: Colors.grey, fontSize: 35),
              ),
              onPressed: () {
                //container动画
                _changeFullScreen(true);
              },
            )),
          ),
        ],
      ),
    );
  }
}
